class EvenDistWeightsEdgeGen(object):
    '''
    classdocs
    '''


    def __init__(self, selfLoopWeight):
        '''
        Constructor
        '''
        self.selfLoopWeight = selfLoopWeight
        
    def Apply(self, network):
        for agent in network.agentList:
            outDegree = network.graph.out_degree([agent])[agent]
            curAgentSelfEdgeWeight = self.selfLoopWeight
            if outDegree == 1:
                curAgentSelfEdgeWeight = 1
            
            for nbr in network.graph.neighbors_iter(agent):
                curNbrWeight = 0
                if (nbr == agent):
                    curNbrWeight = float(curAgentSelfEdgeWeight)
                else:
                    curNbrWeight = (1 - curAgentSelfEdgeWeight) / float(outDegree - 1)
                
                network.graph[agent][nbr]["weight"] = curNbrWeight